package com.cellulam.framework.core.rest;

import com.cellulam.framework.core.log.LogClient;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;

/**
 * 带日志的rest client
 */
public class LogRestClient extends RestClient {

    public LogRestClient(LogClient logClient, int timeout) {
        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectionRequestTimeout(timeout);
        httpRequestFactory.setConnectTimeout(timeout);
        httpRequestFactory.setReadTimeout(timeout);

        this.setRequestFactory(new BufferingClientHttpRequestFactory(httpRequestFactory));

        this.getInterceptors().add(new LoggingClientHttpRequestInterceptor(logClient));
//        this.getInterceptors().add(new JsonMimeInterceptor());
    }
}
